buildMapを使ったAssetBundleBuildについて
概要
AssetBundleを組み立てる方法として、buildMapってのがある。
簡単に言うと、arrayでAssetBundleの指定ができる。
AssetBundleBuildインスタンスにはstring assetBundleNameと、string assetBundleVariant、string[] assetNamesという3つのプロパティがある。
mapping
こんな書き方ができる。
var buildMap = new AssetBundleBuild[2];
// set bundle name and contained contents to map for No 0.
{
var bundle_0AssetPaths = new string[1];
bundle_0AssetPaths[0] = "Assets/scr1.png";
buildMap[0].assetBundleName = "bundle_0.assetbundle";
buildMap[0].assetNames = bundle_0AssetPaths;
}
// No 1.
{
var bundle_1AssetPaths = new string[1];
bundle_1AssetPaths[0] = "Assets/scr2.png";
buildMap[1].assetBundleName = "bundle_1.assetbundle";
buildMap[1].assetNames = bundle_1AssetPaths;
}
BuildPipeline.BuildAssetBundles("somewhere", buildMap, BuildAssetBundleOptions.None, BuildTarget.iOS);
使い所
BuildAssetBundle()の代わりに、単体でAssetBundleを作るのにつかえそうな気がする。
BuildAssetBundle()さんが死亡したんで、使えると嬉しいが、Push, Popに相当するものはあるんだろうか。
-> なさそう
依存関係とかはどうすれば良いんだろう? -> 指定して実行してみた
var buildMap = new AssetBundleBuild[3];
// set bundle name and contained contents to map for No 0.
{
var bundle_0AssetPaths = new string[1];
bundle_0AssetPaths[0] = "Assets/scr1.png";
buildMap[0].assetBundleName = "bundle_0.assetbundle";
buildMap[0].assetNames = bundle_0AssetPaths;
}
// No 1.
{
var bundle_1AssetPaths = new string[1];
bundle_1AssetPaths[0] = "Assets/scr2.png";
buildMap[1].assetBundleName = "bundle_1.assetbundle";
buildMap[1].assetNames = bundle_1AssetPaths;
}
// No 2. depends on same asset in No 0 and 1.
{
var bundle_2AssetPaths = new string[2];
bundle_2AssetPaths[0] = "Assets/scr1.png";
bundle_2AssetPaths[1] = "Assets/scr2.png";
buildMap[2].assetBundleName = "bundle_2.assetbundle";
buildMap[2].assetNames = bundle_2AssetPaths;
}
BuildPipeline.BuildAssetBundles("somewhere", buildMap, BuildAssetBundleOptions.None, BuildTarget.iOS);
青、オレンジそれぞれが同じAssetを指している。
たぶんindexの若い順に解決されて、後半のものが依存になるのでは?
→実行時にエラーが出る。
Asset "Assets/scr1.png" has been marked into more than one AssetBundles.
UnityEditor.BuildPipeline:BuildAssetBundles(String, AssetBundleBuild[], BuildAssetBundleOptions, BuildTarget)
この方法では、ひとつのAssetは一つのassetNamesに対してしか登録できず、依存は書けないっぽい。
解決法
buildMapを使った場合の依存の書き方はなくって、
依存は勝手に解決される、というのが答えだった。
概念的には、
・依存は勝手に解決される
・オリジナルを明示することはできないので、どこに依存Assetが入るかを指定する方法はない
という感じだった。
具体的な例を用意中。